package util.i;

import util.j.Shuchu;
import util.t.DS;
import util.t.tiliList;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.Date;

import static java.lang.System.currentTimeMillis;

public class Shuchuimpl implements Shuchu {
    JTextArea area;
    public void setText3(JTextArea area) {
        this.area=area;
    }
    tiliList list;
    public void setlist(tiliList list) {
        this.list=list;
    }

    public void actionPerformed(ActionEvent e) {
        try {
            SimpleDateFormat sdf= new SimpleDateFormat("HH:mm");
            SimpleDateFormat sdfbj= new SimpleDateFormat("dd");
            Date date=new Date(currentTimeMillis());
            Writer w=new FileWriter("清体力.txt");
            String t1=sdfbj.format(date);
            String t2=sdfbj.format(list.list.first().getDate());
            if(t1.equals(t2)){
                w.write("请在 今日 "+sdf.format(list.list.first().getDate())+"之前上线，不然  "+list.list.first().getName()+"  的体力会溢出哟");
            }else {
                w.write("请在 明日 "+sdf.format(list.list.first().getDate())+"之前上线，不然  "+list.list.first().getName()+"  的体力会溢出哟");
            }

            w.write("\n\n");
            w.write(area.getText());
            w.write("\n\n");
            w.write("清体力顺序：\n");
            for(DS it:list.list){
                w.write(it.getName()+"\n");
            }
            w.flush();
            w.close();

        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}
